//字符串参数替换
//'爱 %3 上了 %1 肯德 %2 基拉%3克丝%4建档立卡介%%绍的老%%%卡就死%123456665定了空间啊 %99 路上看到骄傲了可视对讲'.arg('aaa','bbb','ccc','ddd','eee')
String.prototype.arg = function() {
    var replaceStrArr = arguments;
    var resultArr = this.match(/\s%[0-9]+\s/g);
    resultArr.sort(function(a, b) {
        return a.substr(2) * 1 - b.substr(2) * 1
    })
    var resultObj = {
        len: 0
    }
    for (var i = 0, len = resultArr.length; i < len; i++) {
        var result = resultArr[i];
        if (resultObj[result] == undefined) {
            resultObj[result] = resultObj.len++;
        }
    }
    var argStr = this.replace(/\s%[0-9]+\s/g, function(e) {
        var replaceStr = replaceStrArr[resultObj[e]];
        if (replaceStr != undefined) {
            return replaceStr;
        } else {
            return e;
        }
    })
    return argStr;
};
String.prototype.htmlEntities = function(Decode) {
    var returnStr,
        conElement = document.createElement('div');
    if (Decode === undefined) {
        conElement.innerText = this;
        returnStr = conElement.innerHTML.replace(/ /g, '&nbsp;');
    } else {
        conElement.innerHTML = this;
        returnStr = conElement.innerText;
    }
    conElement = null;
    return returnStr;
};

String.prototype.urlToObj = function() {
    var reg = /([^?&=]+)=([^?&=]+)/g;
    var res = null,
        obj = {};
    while (res = reg.exec(this)) {
        obj[res[1]] = decodeURI(res[2]);
    }
    return obj;
}

//获取当月第一天的星期几
Date.prototype.getMonthFirstDay = function() {
        return (new Date(this.getFullYear(), this.getMonth(), 1)).getDay();
    }
    //获取当月一共多少天
Date.prototype.getMonthDateMax = function() {
        return (new Date(this.getFullYear(), this.getMonth() + 1, 0)).getDate();
    }
    //获取当天零点时间戳
Date.prototype.getDayTime = function() {
        return (new Date(this.getFullYear(), this.getMonth(), this.getDate())).getTime();
    }
    //获取当天零点时间戳
Date.prototype.getSecondTime = function() {
        return Math.floor(this.getTime() / 1000);
    }
    //判断是否为同一天
Date.prototype.isSameDay = function(date2) {
        return this.getFullYear() == date2.getFullYear() && this.getMonth() == date2.getMonth() && this.getDate() == date2.getDate() ? true : false;
    }
    //判断是否为同一天
Date.prototype.timeOffset = function(timeNum) {
    return new Date(this.getTime() + timeNum);
}
Date.prototype.changeMonth = function(n) {
    var newYear = this.getFullYear();
    var newMonth = this.getMonth() + n;
    var newDate = this.getDate()
    if (newMonth >= 0) {
        newYear = newYear + Math.floor(newMonth / 12);
        newMonth = newMonth % 12;
    } else {
        newYear = newYear + Math.floor(newMonth / 12);
        newMonth = 12 + newMonth % 12;
    }
    var DateNew = new Date(newYear, newMonth, 1);
    if (newDate > DateNew.getMonthDateMax()) {
        newDate = DateNew.getMonthDateMax()
    }
    return new Date(newYear, newMonth, newDate);
}
Date.prototype.Format = function(fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "N+": this.getMonth(), //月份
        "D+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒 //季度
        "S": this.getMilliseconds(), //毫秒
        "q+": Math.floor((this.getMonth() + 3) / 3)
    };
    if (/(Y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
    };
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)))
        };
    }
    return fmt;
    /*
      var time1 = dateNow().Format("YYYY-MM-DD");
    var time2 = dateNow().Format("YYYY-MM-DD hh:mm:ss");
      */
}

//获取时区时间
Date.prototype.timeZoneDate = function(targetTimeZoneOffset) {
    var dateObj = this;
    var loaclTimeZoneOffset = dateObj.getTimezoneOffset() / 60;

    if (targetTimeZoneOffset === undefined) {
        if (Date.timeZoneOffset !== undefined) {
            targetTimeZoneOffset = Date.timeZoneOffset;
        } else {
            targetTimeZoneOffset = loaclTimeZoneOffset;
        }
    }
    //targetTimeZoneOffset=Date.timeZoneOffset;
    var showTime = dateObj.getTime() + (loaclTimeZoneOffset - targetTimeZoneOffset) * 60 * 60 * 1000;
    var showDate = new Date(showTime);
    showDate.getTime = function() {
        return dateObj.getTime();
    };
    return showDate;
}

Date.prototype.CountdownTime = function(endTime, fmt) {
    var myTime = this.getTime();
    var difTime = endTime - myTime;
    if (difTime < 0) {
        difTime = 0;
    }
    if (fmt) {
        if (typeof fmt == 'function') {
            fmt = fmt(difTime);
        }
        var difDD = Math.floor(difTime / (24 * 60 * 60 * 1000));
        var difhh = Math.floor((difTime % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
        var difmm = Math.floor((difTime % (60 * 60 * 1000)) / (60 * 1000));
        var difss = Math.floor((difTime % (60 * 1000)) / 1000);
        var o = {
            "D+": difDD, //日
            "h+": difhh, //小时
            "m+": difmm, //分
            "s+": difss
        };
        if (/(Y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
        };
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)))
            };
        }
        return fmt;
    } else {
        return difTime;
    }
}




//解决ie8下 Array不支持indexOf
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(elt /*, from*/ ) {
        var len = this.length >>> 0;

        var from = Number(arguments[1]) || 0;
        from = (from < 0) ? Math.ceil(from) : Math.floor(from);
        if (from < 0)
            from += len;

        for (; from < len; from++) {
            if (from in this &&
                this[from] === elt)
                return from;
        }
        return -1;
    };
}
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
    return this;
};

Array.prototype.mergeSort = function(callback) {
    var rootArr = this;

    function arrayMergeSort(arr, callback) {

        function merge(left, right, callback) {
            var result = [];
            while (left.length > 0 && right.length > 0) {
                if (callback(left[0], right[0]) <= 0) {
                    result.push(left.shift());
                } else {
                    result.push(right.shift());
                }
            }
            return result.concat(left).concat(right);
        }

        if (arr.length <= 1) return arr;
        var middle = Math.floor(arr.length / 2),
            left = arr.slice(0, middle),
            right = arr.slice(middle);

        return merge(arrayMergeSort(left, callback), arrayMergeSort(right, callback), callback);
    }
    if (callback == undefined) {
        this.sort();
    } else {
        rootArr = arrayMergeSort(rootArr, callback);
        this.length = 0;
        Array.prototype.push.apply(this, rootArr)
    }
    return rootArr;
}







;
(function($) {
    $.each(['show', 'hide'], function(i, ev) {
        var el = $.fn[ev];
        $.fn[ev] = function() {
            this.trigger(ev);
            return el.apply(this, arguments);
        };
    });
})(jQuery);


(function($) {
    var domTopZIndex = 10000;
    $.extend({
        parseInt: function(str) {
            str = str + '';
            var parseNumber;

            function tryToNum(s) {
                var num = false;
                /*num=Number(s);
                if(isNaN(num)===false){
                return num;
                }*/
                num = parseInt(str);
                if (isNaN(num) === false) {
                    return num;
                }
                return false;
            }
            parseNumber = tryToNum(str);
            if (parseNumber !== false) {
                return parseNumber;
            }
            str = str.replace(/[^\d]*/g, '');
            parseNumber = tryToNum(str);
            if (parseNumber !== false) {
                return parseNumber;
            }

            return 0;
        },
        zeroDigit: function(n, l) {
            l = l || 2;
            var s = n + '';
            while (s.length < l) {
                s = '0' + s;
            }
            return s;
        },
        urlGet: function(urlStr) {
            if (urlStr == undefined) {
                urlStr = window.location.search
            }
            var aQuery = urlStr.split("?"); //取得Get参数
            var aGET = new Array();
            if (aQuery.length > 1) {
                var aBuf = aQuery[1].split("&");
                for (var i = 0, iLoop = aBuf.length; i < iLoop; i++) {
                    var aTmp = aBuf[i].split("="); //分离key与Value
                    aGET[aTmp[0]] = aTmp[1];
                }
                aGET['length'] = i;
            }
            return aGET;
        },
        locationHash: function(newHashData, onlyTranslateHashStr) {
            function getHashData(hashStr) {
                hashStr = hashStr.substr(1);
                if (hashStr === '') {
                    return false;
                }
                var hashArr = hashStr.split(',');
                var hashObj = {};
                $.each(hashArr, function(i, c) {
                    var cArr = c.split(':');
                    hashObj[cArr[0]] = cArr[1];
                });
                return hashObj;
            }

            function setLocationHash(hashData) {
                function setByObj(hashObj) {
                    var hashStr = '';
                    $.each(hashData, function(k, v) {
                        hashStr += ',' + k + ':' + v;
                    });
                    hashStr = '#' + hashStr.substr(1);
                    if (onlyTranslateHashStr !== true) {
                        window.location.hash = hashStr;
                    }
                    return hashStr;
                }

                function setbyStr(hashStr) {
                    if (onlyTranslateHashStr !== true) {
                        window.location.hash = hashStr;
                    } else {
                        return getHashData(hashStr);
                    }
                }
                switch (typeof hashData) {
                    case 'object':
                        return setByObj(hashData);
                        break;
                    case 'string':
                        return setbyStr(hashData);
                        break;
                }
            }
            if (newHashData === undefined) {
                return getHashData(window.location.hash);
            } else {
                return setLocationHash(newHashData);
            }
        },
        n2br: function(s) {
            s = s.replace(new RegExp("\n", "g"), "<br>");
            return s;
        },
        inBrowser: function(bsCallback, qtCallback) {
            if (window.widget && window.widget.serverDate && qtCallback) {
                qtCallback();
            } else if (bsCallback) {
                bsCallback();
            }
        },
        newDate: function(dateValue, maybeSecond) {
            function newDateByStr(dateStr) {
                var dateArr = dateStr.replace(/\D+/g, ',').replace(/(^\,|\,$)/g, '').split(',');
                if (dateArr.length < 3 || dateArr.length > 7) {
                    console.error('$.newDate arguments error!');
                    return undefined;
                }
                dateArr[1]--;
                return newDateByArray(dateArr);
            }

            function newDateByArray(dateArr) {
                if (dateArr.length < 3 || dateArr.length > 7) {
                    console.error('$.newDate arguments error!');
                    return false;
                }
                return new Date(Date.UTC.apply(this, dateArr) + (new Date).getTimezoneOffset() * 60 * 1000);
            }

            function newDateByTimestamp(timestamp) {
                if (maybeSecond === true && timestamp < 31507200000) {
                    //可能是来自服务器的秒数,且时间戳早于1971年且
                    timestamp = timestamp * 1000;
                }
                return new Date(timestamp);
            }

            function newDateByNow() {
                return new Date();
            }
            if (arguments.length > 2) {
                return newDateByArray(arguments);
            } else {
                switch (typeof dateValue) {
                    case 'number':
                        return newDateByTimestamp(dateValue);
                        break;
                    case 'string':
                        return newDateByStr(dateValue);
                    case 'object':
                        return newDateByStr(dateValue);
                        break;
                    case 'undefined':
                        return newDateByNow();
                        break;
                    default:
                        console.error('$.newDate arguments type error!');
                }
            }
        },
        newTimeZoneDate: function() {
            return ($.newDate.apply(this, arguments)).timeZoneDate($.timeZoneSn);
        },
        getServerDate: function(callback) {
            /*setTimeout(function(){
            var serverNowTime=new Date().getTime();
            callback(serverNowTime);
            },200)*/
            $.ajax({
                type: 'get',
                url: window.location.href,
                async: true,
                complete: function(xhr, data) {
                    var serverDate = xhr.getResponseHeader('Date');
                    if (serverDate === null) {
                        console.error('browser get server date error');
                        serverDate = new Date();
                    } else {
                        serverDate = new Date(serverDate);
                    }
                    callback(serverDate);
                }
            });
        },
        timeHistoryText: function(historyDateTime, nowDateTime) {

            //timeDeviation
            nowDateTime = nowDateTime || $.newDate().getTime();

            var historyDateStartTime = (new Date(historyDateTime)).getDayTime();
            var nowDateStartTime = (new Date(nowDateTime)).getDayTime();

            var dateMarkText = '';
            if (historyDateStartTime < nowDateStartTime) {
                var dayDeviation = Math.floor((nowDateStartTime - historyDateStartTime) / (24 * 60 * 601000));
                if (dayDeviation < 1) {
                    dateMarkText = '昨天'
                } else if (dayDeviation < 2) {
                    dateMarkText = '前天'
                } else {
                    dateMarkText = (new Date(historyDateTime)).Format('MM-DD hh:mm');
                }
            } else {
                if (historyDateTime < nowDateTime) {
                    dateMarkText = (new Date(historyDateTime)).Format('hh:mm');
                } else {
                    dateMarkText = (new Date(historyDateTime)).Format('MM-DD hh:mm');
                }
            }
            return dateMarkText;
        },
        timeLengthText: function(timeLength) {
            var strData = {
                D: {
                    name: '天',
                    value: 0
                },
                h: {
                    name: '小时',
                    value: 0
                },
                m: {
                    name: '分钟',
                    value: 0
                },
                s: {
                    name: '秒',
                    value: 0
                }
            }
            var timeCalc = timeLength;

            function hasUnit(unitValue, parentUnitScale) {
                var baseV = timeLength;
                if (parentUnitScale !== undefined) {
                    baseV = timeLength % (unitValue * parentUnitScale);
                }
                baseV = Math.floor(baseV / unitValue);
                return baseV;
            }
            strData.s.value = (hasUnit(1000, 60));
            strData.m.value = (hasUnit(1000 * 60, 60));
            strData.h.value = (hasUnit(1000 * 60 * 60, 24));
            strData.D.value = (hasUnit(1000 * 60 * 60 * 24));


            function outputStr(vArr) {
                var strText = '';
                var parentHasValue = false;
                var emptyText = '';
                $.each(vArr, function(i, vData) {
                    if (vData.value > 0) {
                        parentHasValue = true;
                        strText += vData.value + vData.name + ' ';
                    } else {
                        if (parentHasValue === true) {
                            strText += '0' + vData.name + ' ';
                        }
                    }
                    emptyText = '0' + vData.name;
                });
                if (strText === '') {
                    return emptyText;
                } else {
                    return strText;
                }

            }
            return outputStr([strData.D, strData.h, strData.m, strData.s]);
        },
        isArray: function(obj) {
            return Object.prototype.toString.call(obj) === '[object Array]';
        },
        /*getArrByAttr: function(obj, attr) {
        var arr = [];
        $.each(obj, function(index, value) {
        if (value != undefined) {
        arr.push(value[attr]);
        }
        });
        return arr;
        },*/
        addTrigger: function(obj, triggerName) {
            var triggerList = [];
            var triggerOneList = [];
            obj[triggerName] = function() {
                var triggerLength = arguments.length;
                if (triggerLength > 0) {
                    switch (arguments[triggerLength - 1]) {
                        case 'remove':
                            for (var i = 0; i < triggerLength - 1; i++) {
                                triggerList.remove(arguments[i]);
                                triggerOneList.remove(arguments[i]);
                            }
                            break;
                        case 'one':
                            for (var i = 0; i < triggerLength - 1; i++) {
                                triggerOneList.push(arguments[i]);
                            }
                            break;
                        default:
                            for (var i = 0; i < triggerLength; i++) {
                                triggerList.push(arguments[i]);
                            }
                    }
                } else {
                    $.each(triggerList, function(i, triggerFn) {
                        if (typeof triggerFn === 'function') {
                            triggerFn();
                        } else {
                            console.error('$.addTrigger: Argument [' + triggerFn + '] is not a function!')
                        }

                    });
                    $.each(triggerOneList, function(i, triggerFn) {
                        if (typeof triggerFn === 'function') {
                            triggerFn();
                        } else {
                            console.error('$.addTrigger: Argument [' + triggerFn + '] is not a function!')
                        }
                    });
                    triggerOneList = [];
                }
            }
        },
        parentIframeDom: function() {
            var parentIframeDom = undefined;
            $(window.parent.document).find('iframe').each(function() {
                var iframeDom = this;
                if (iframeDom.contentWindow === window) {
                    parentIframeDom = iframeDom;
                }
            })
            return parentIframeDom;
        },
        dataDomSort: function(domDataList, dataDomName, $parentContainer, sortCallback, mergeSort) {
            var domListArr = [];
            for (var k in domDataList) {
                var domData = domDataList[k];
                domListArr.push(domData);
            }
            if (mergeSort) {
                domListArr.mergeSort(sortCallback);
            } else {
                domListArr.sort(sortCallback);
            }

            for (var i = 0, len = domListArr.length; i < len; i++) {
                var dataDom = domListArr[i][dataDomName];
                var domSn = $parentContainer.children().index(dataDom.$dom);
                if (domSn != i) {
                    var $nextDataDom = $parentContainer.children().eq(i);
                    $nextDataDom.before(dataDom.$dom);
                }
            }
        },
        zIndexTop: function($dom) {
            $dom.css('z-index', function(index, value) {
                value = $.parseInt(value);
                if (value < domTopZIndex) {
                    return ++domTopZIndex;
                } else {
                    return value;
                }

            });
        },
        objectSearch: function(config) {
            var targetObj = config.targetObj || {};
            var searchKeywordFilter = config.keyword || [];
            var searchCallback = config.searchCallback || function() {};
            var searchResultList = [];

            function searchObjectChild(childData) {
                $.each(searchKeywordFilter, function(i, filterData) {
                    var keyName = filterData.keyName;
                    var keywordText = filterData.keyValue;
                    if (String(childData[keyName]).indexOf(String(keywordText)) >= 0) {
                        searchResultList.push(childData);
                        return false;
                    }
                });
            }
            $.each(targetObj, function(i, targetChildData) {
                searchObjectChild(targetChildData);
            });

            searchCallback(searchResultList);

            return searchResultList;

        },
        getDefined: function(argValue, defValue) {
            var argList = Array.prototype.slice.call(arguments);
            var definedVal = undefined;
            $.each(argList, function(i, arg) {
                if (arg !== undefined) {
                    definedVal = arg;
                    return false;
                }
            });
            return definedVal;
        },
        addMouseWheelRangeEventListener: function(config) {
            /*$.addMouseWheelRangeEventListener({
            $window:$(window),
            up:function(){
            runPage.prev();
            },
            down:function(){
            runPage.next();
            }
            });*/
            var eListener = this;
            eListener.disabled = false;
            eListener.wheelLength = 0;
            eListener.wheelRange = config.range || 3;
            eListener.$window = config.$window || $(window);
            eListener.up = config.up || function() {};
            eListener.down = config.down || function() {};

            function wheelCallback() {
                if (eListener.disabled === false) {
                    eListener.disabled = true;
                    if (eListener.wheelLength > 0) {
                        eListener.up();
                    }
                    if (eListener.wheelLength < 0) {
                        eListener.down();
                    }

                    setTimeout(function() {
                        eListener.disabled = false;
                        eListener.wheelLength = 0;
                    }, 800)
                }
            }
            var resetWheelLengthTimeout;

            function resetRunPageWheelRange() {
                clearTimeout(resetWheelLengthTimeout);
                resetWheelLengthTimeout = setTimeout(function() {
                    eListener.wheelLength = 0;
                }, 400);
            }
            eListener.$window.on('mousewheel', function(e, d) {
                eListener.wheelLength += d;
                //console.log(eListener.wheelLength);
                if (eListener.wheelLength > eListener.wheelRange || eListener.wheelLength < -eListener.wheelRange) {
                    if (eListener.disabled === false) {
                        wheelCallback();
                    }
                }
                resetRunPageWheelRange();
            })
        },
        /*
        返回函数去抖的版本
        @param func 传入函数
        @parem wait 延迟毫秒数
        @param immediate 是否在wait时间间隔开始即调用，默认为true
        @return function
        */
        debounce: function(func, wait, immediate) {
            var timeout, args, context, timestamp, result;

            function now() {
                return Date.now() || (new Date().getTime())
            }
            var later = function() {
                var last = now() - timestamp;

                if (last < wait && last >= 0) {
                    timeout = setTimeout(later, wait - last);
                } else {
                    timeout = null;
                    if (!immediate) {
                        result = func.apply(context, args);
                        if (!timeout) context = args = null;
                    }
                }
            };

            return function() {
                context = this;
                args = arguments;
                timestamp = now();
                var callNow = immediate && !timeout;
                if (!timeout) timeout = setTimeout(later, wait);
                if (callNow) {
                    result = func.apply(context, args);
                    context = args = null;
                }

                return result;
            };
        },

        /**
         * [getTimeStamp 获取时间戳]
         * @param string|number|Date 同传入new Date()的参数
         * @return number 标准时间戳
         */
        toTimeStamp: function (val) {
          var getDate = (val == undefined) ? (new Date()) : (new Date(val));
          return Math.floor(getDate.getTime() / 1000);
        },
        /**
         * [toDate 获取Date]
         * @param string|number 标准时间戳
         * @return Date 
         */
        toDate: function (val) {
          if(val == undefined) {
            return new Date()
          }
          return new Date(Number(val)*1000)
        }

    });
    $.fn.extend({
        value: function(newValue) {
            var $this = $(this);
            if (newValue !== undefined) {
                if ($this.attr('data-value') !== undefined) {
                    $this.attr('data-value', newValue);
                }
                $this.val(newValue);
                return $this;
            }
            var defaultValue = $this.attr('data-tips');
            var dataValue = $this.attr('data-value');
            var showValue = $this.val();
            var trueValue = '';
            if (defaultValue === undefined) {
                defaultValue = '';
            }
            if (dataValue !== undefined) {
                trueValue = dataValue;
            } else {
                trueValue = showValue;
            }
            if (trueValue !== defaultValue) {
                return trueValue;
            } else {
                return '';
            }
        },
        valueReset: function() {
            var $this = $(this);
            var defaultValue = $this.attr('data-tips');
            if (defaultValue === undefined) {
                defaultValue = '';
            }
            $this.removeClass('focus').removeAttr('data-value').val(defaultValue);
            return this;
        },
        singleChecked: function() {
            $(this).addClass('checked').siblings().removeClass('checked');
        },
        singleActive: function() {
            $(this).addClass('active').siblings().removeClass('active');
        },
        inWindow: function() {
            var windowRect = {
                    left: 0,
                    top: 0,
                    right: $(window).width(),
                    bottom: $(window).height()
                },
                callback = function() {},
                edgeCheck = false;
            for (var i = 0, len = arguments.length; i < len; i++) {
                var argument = arguments[i];
                if (typeof argument == 'string') {
                    var $argument = $(argument);
                    if ($argument.length > 0) {
                        windowRect = $argument[0].getBoundingClientRect();
                    }
                }
                if (argument instanceof jQuery) {
                    windowRect = argument[0].getBoundingClientRect();
                }
                if (typeof argument == 'function') {
                    callback = argument;
                }
                if (typeof argument == 'boolean') {
                    edgeCheck = argument;
                }
            }
            var domRect = this[0].getBoundingClientRect();
            if (edgeCheck) {
                if (
                    domRect.left < windowRect.left ||
                    domRect.top < windowRect.top ||
                    domRect.right > windowRect.right ||
                    domRect.bottom > windowRect.bottom
                ) {
                    return false;
                }
            } else {
                if (
                    domRect.left >= windowRect.right ||
                    domRect.top >= windowRect.bottom ||
                    domRect.right <= windowRect.left ||
                    domRect.bottom <= windowRect.top
                ) {
                    return false;
                }
            }
            callback();
            return true;
        }
    });
})(jQuery);


var consoleDebug = true;
if (!console) {
    console = {};
}
console._debug = function() {
    if (consoleDebug) {
        var debugArgArr = Array.prototype.slice.call(arguments);
        var debugLogArr = [];
        var debugFunArr = [];
        $.each(debugArgArr, function(i, debugArg) {
            switch (typeof debugArg) {
                case 'function':
                    debugFunArr.push(debugArg);
                    break;
                default:
                    debugLogArr.push(debugArg);
            }
        });
        var consoleDebugFn = console.debug;
        try {
            consoleDebugFn.apply(null, debugLogArr);
        } catch (e) {
            console.log('console_debug', e);
            var debugLogStr = debugLogArr.join(',');
            consoleDebugFn(debugLogStr);
        }
        $.each(debugFunArr, function(i, debugFun) {
            debugFun();
        });
    }
}
var requireLoad = {
    hasReady: false,
    callback: {
        length: 0
    },
    ready: function(fn) {
        var $require = this;
        if (fn && typeof fn == "function") {
            if ($require.hasReady) {
                fn();
            } else {
                $require.callback[$require.callback.length] = fn;
                $require.callback.length++
            }
        }
    },
    isReady: function() {
        var $require = this;
        $require.hasReady = true;
        for (var i = 0, len = $require.callback.length; i < len; i++) {
            $require.callback[i]();
            delete $require.callback[i];
        }
        $require.callback.length = 0;
    }
}

var global = {};
var isServerLocation = false;
var serverPathName = '';
var getImgCropedSrc = function(imgSrc, cropSize) {
    //if(imgSrc===''){
    if (!imgSrc) {
        return '';
    }
    var cropSizeData = cropSize.split('x');
    return '/upload/images/' + imgSrc.replace('.', '_' + cropSizeData[0] + '.');
}

function serverLocationCheck() {
    var windowLocationPathName = ''
    switch (window.location.hostname) {
        case 'www.eeo13.test':
        case 'www.eeo.cn':
            isServerLocation = true;
            break;
        default:
            isServerLocation = false;
    }
    //serverPathName=windowLocationPathName;
}
var serverAjaxAPIUrl = {
    imgUpload: '/ajax/upload_do.php?action=image'
}
serverLocationCheck();

function serverHref(pageFileName) {
    var fullUrl = '';
    pageFileName = pageFileName.replace('.html', '');
    if (isServerLocation) {
        fullUrl = 'index.php?page=' + pageFileName;
    } else {
        fullUrl = pageFileName + '.html'
    }
    return fullUrl;
}

/**
 * [ClassChimp Addtion]
 *
 */
Date.prototype.getDayText || (Date.prototype.getDayText = function () {
  var dayTextArr = ['日','一','二','三','四','五','六']
  return dayTextArr[this.getDay()]
})

Date.prototype.getDaytext || (Date.prototype.getDaytext = function () {
    var dayTextArr = ['7', '1', '2', '3', '4', '5', '6']
    return dayTextArr[this.getDay()]
})

/*
$.ajax方法的封装
@param config 以对象传入，参数和$.ajax方法一致，config必须的属性为url和success回调
*/

var errorShow = false;
function ajaxMethod(config) {
  config || (config = {})
  if(!config.url || !config.success) {
    return false
  }

  if(config.method && config.method.toLowerCase().indexOf('p') > -1) {
    console.log(config.data);
  }

  var popFlag = true;
  _Waiting.show();

  $.ajax({
    url: config.url,
    method: config.method || config.type || 'get',
    data: config.data || {},
    dataType: config.dataType || 'json',
    success: function (data, textStatus, jqXHR) {
      if(popFlag) {
        popFlag = false;
        _Waiting.close();
      }
      if(typeof data != 'object') {
        data = JSON.parse(data);
      }

      if (errorShow) {
        _Tips(data.status.message);
      }
      config.success(data.data, data.status, textStatus, jqXHR);
    },
    async: (config.async == undefined ? true : config.async),
    error: config.error || function (xhr, textStatus, errorThrown) {
      if(popFlag) {
        popFlag = false;
        _Waiting.close();
      }
      console.log(arguments);
    },
    complete: function(request, statusText) {
      if(popFlag) {
        popFlag = false;
        _Waiting.close();
      }
    }
  })
}


/*
判断当前页面是否在框架中
@return Boolean
*/
function isIframe(){
  if (window.top != window.self) {
    return true
  }
  return false
}

function getDurationMinute(begindate, enddate) {
  var beginTime = +new Date(begindate.replace('T',' '));
  var endTime = +new Date(enddate.replace('T',' '));
  return (endTime - beginTime) / (60 * 1000);
}

function addZero(num) {
  if(isNaN(num)) {
  return '00';
  }
  return num<10 ? ('0'+num) : num;
}


/**
 * 格式化服务器传来的带T的字符串时间
 * @param  {string} timeStr 字符串时间
 * @return {string}         前端标准的字符串时间表示
 */
function formatTime(timeStr) {
  if(typeof timeStr == 'string') {
  return timeStr.replace('T', ' ');
  }
  return '';
}

function getCourseColorById(courseList, id) {
    for (var i = 0; i < courseList.length; i++) {
      if(courseList[i].key == id) {
        return courseList[i].color;
      }
    }
    return '';
  }

function getCourseNameById(courseList, id) {
  for (var i = 0; i < courseList.length; i++) {
    if(courseList[i].key == id) {
      return courseList[i].label;
    }
  }
  return '';
}
